home *** CD-ROM | disk | FTP | other *** search
/ SGI Performance Co-Pilot 1.3 / SGI Performance Co-Pilot 1.3.iso / dist / dist6.4 / pcp.idb / usr / sbin / mpvis.z / mpvis
Text File  |  1997-04-03  |  8KB  |  356 lines

  1. #!/bin/sh
  2. #  Copyright (c) 1994 Silicon Graphics, Inc.
  3. #  ALL RIGHTS RESERVED.
  4. #  U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND
  5. #  Use, duplication or disclosure by the Government is subject to
  6. #  restrictions as set forth in FAR 52.227.19(c)(2) or subparagraph
  7. #  (c)(1)(ii) of the Rights in Technical Data and Computer Software clause
  8. #  at DFARS 252.227-7013 and/or similar or successor clauses in the FAR,
  9. #  or the DOD or NASA FAR Supplement.  Contractor/manufacturer is Silicon
  10. #  Graphics, Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
  11. #  THIS SOFTWARE CONTAINS CONFIDENTIAL AND PROPRIETARY INFORMATION OF
  12. #  SILICON GRAPHICS, INC.  ANY DUPLICATION, MODIFICATION, DISTRIBUTION, OR
  13. #  DISCLOSURE IS STRICTLY PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN
  14. #  PERMISSION OF SILICON GRAPHICS, INC.
  15. # /
  16.  
  17. #
  18. # $Id: mpvis.sh,v 2.14 1997/03/21 08:51:15 kenmcd Exp $
  19. #
  20.  
  21. tmp=/tmp/$$
  22. trap "rm -f $tmp.*; exit" 0 1 2 3  15
  23. rm -f $tmp.*
  24.  
  25. gridspace=120
  26. cpuargs=
  27.  
  28. algorithm="k"
  29. force=false
  30. maxrowlen=16
  31. verbose=false
  32. showinst=false
  33. version="2"
  34.  
  35. . /usr/pcp/lib/pmview-args
  36.  
  37. _usage()
  38. {
  39.     echo >$tmp.msg 'Usage: mpvis [options] [cpuid...]
  40.  
  41. options:
  42.   -b              use row:column ratio of 1:8 (soft limit)
  43.   -i              show CPU numbers (version 2 only)
  44.   -r rowlen       maximum number of CPUs per row (soft limit) [default 16]
  45.   -R rowlen       force this number of CPUs per row
  46.   -v version      generate scene for different versions of pmview [default 2]
  47.   -V              verbose/diagnostic output  
  48.  
  49. pmview(1) options:'
  50.  
  51.     _pmview_usage >>$tmp.msg
  52.     echo >>$tmp.msg
  53.     echo 'Default title is: CPU Utilization for Host' >>$tmp.msg
  54.     _pmview_info -f $tmp.msg
  55. }
  56.  
  57. # generate one row of the scene
  58. #
  59. _do_row()
  60. {
  61. cat <<End-of-File >>$tmp.conf
  62.     _grid 0 $y show (
  63.     _labeledbar (
  64.         _metrics (
  65.                 irix.kernel.percpu.cpu.idle[$rowlist]        1000
  66.                 irix.kernel.percpu.cpu.wait.total[$rowlist]  1000
  67. End-of-File
  68. $have_intr && echo "                irix.kernel.percpu.cpu.intr[$rowlist]        1000" >>$tmp.conf
  69. cat <<End-of-File >>$tmp.conf
  70.                 irix.kernel.percpu.cpu.sys[$rowlist]         1000
  71.                 irix.kernel.percpu.cpu.user[$rowlist]        1000
  72.         )
  73. End-of-File
  74. if $have_intr
  75. then
  76.     echo '        _metriclabels ( "idle" "wait" "intr" "sys" "user" )' >>$tmp.conf
  77. else
  78.     echo '        _metriclabels ( "idle" "wait" "sys" "user" )' >>$tmp.conf
  79. fi
  80. $showinst && echo "        _instlabels away ( $labels )" >>$tmp.conf
  81. cat <<End-of-File >>$tmp.conf
  82.         _colorlist cpu
  83.     )
  84.     )
  85. End-of-File
  86. }
  87.  
  88. _pmview_args "$@"
  89.  
  90. if [ "X$otherArgs" != X ]
  91. then
  92.     while getopts "?biN:r:R:v:V" c $otherArgs    # TODO - delete N for MR
  93.     do
  94.     case $c
  95.     in
  96.         b)
  97.         algorithm="b"
  98.         ;;
  99.         i)
  100.         showinst=true
  101.         gridspace=60
  102.         ;;
  103.         r)
  104.         maxrowlen=$OPTARG
  105.         ;;
  106.         R)
  107.         maxrowlen=$OPTARG
  108.         force=true
  109.         ;;
  110.         v)
  111.         version=$OPTARG
  112.         if [ $version != "1" -a $version != "2" ]
  113.         then
  114.             _pmview_error "only versions 1 and 2 supported for -v"
  115.             # NOTREACHED
  116.         fi
  117.         ;;
  118.         V)
  119.         verbose=true
  120.         ;;
  121.         ?)
  122.         _usage
  123.         exit 1
  124.         ;;
  125.     esac
  126.     done
  127.     set -- $otherArgs
  128.     shift `expr $OPTIND - 1`
  129.  
  130.     [ $# -gt 0 ] && cpuargs=$@
  131. fi
  132.  
  133. # set host and the options variable (options to pminfo - see below)
  134. #
  135. if [ "X$arch" != X ]
  136. then
  137.     host=`pmdumplog -l $arch 2>/dev/null | awk '/^Performance/ {print $5}' | sed -e 's/,//g'`
  138.     [ "X$host" = X ] && host="unknown host"
  139.     host="$host (Archive $arch)"
  140.     options="$namespace -a $arch"
  141. elif [ "X$host" != X ]
  142. then
  143.     options="$namespace -h $host"
  144. else
  145.     host=`hostname`
  146.     options="$namespace"
  147. fi
  148.  
  149. [ -z "$titleArg" ] && titleArg="CPU Utilization for Host $host"
  150.  
  151. # irix.kernel.percpu.cpu.intr not always available
  152. #
  153. have_intr=true
  154. num_intr=`pmprobe $options irix.kernel.percpu.cpu.intr 2>/dev/null | cut -d' ' -f 2`
  155. [ "$num_intr" -lt 1 ] && have_intr=false
  156.  
  157. rm -f $tmp.conf
  158. if [ $version = "1" ]
  159. then
  160.     # pmview 1.0
  161.     #
  162.     cat <<End-of-File >$tmp.conf
  163. # pmview 1.0
  164. #
  165. # mpvis
  166. #
  167. End-of-File
  168.     if $have_intr
  169.     then
  170.     cat <<End-of-File >>$tmp.conf
  171. 5 0  0.0 0.0 0.8   1000.0    user    irix.kernel.percpu.cpu.user
  172. 4 0  0.8 0.0 0.0   1000.0    sys     irix.kernel.percpu.cpu.sys
  173. 3 0  0.8 0.8 0.0   1000.0    intr    irix.kernel.percpu.cpu.intr
  174. 2 0  0.0 0.8 0.8   1000.0    wait    irix.kernel.percpu.cpu.wait.total
  175. 1 0  0.0 0.8 0.0   1000.0    idle    irix.kernel.percpu.cpu.idle
  176. End-of-File
  177.     else
  178.     cat <<End-of-File >>$tmp.conf
  179. 4 0  0.0 0.0 0.8   1000.0    user    irix.kernel.percpu.cpu.user
  180. 3 0  0.8 0.0 0.0   1000.0    sys     irix.kernel.percpu.cpu.sys
  181. 2 0  0.0 0.8 0.8   1000.0    wait    irix.kernel.percpu.cpu.wait.total
  182. 1 0  0.0 0.8 0.0   1000.0    idle    irix.kernel.percpu.cpu.idle
  183. End-of-File
  184.     fi
  185.  
  186. else
  187.     # pmview 2.0
  188.     #
  189.  
  190.     # create the list of cpus to be displayed - get inventory
  191.     #
  192.     eval `pmprobe $options -I irix.kernel.percpu.cpu.user 2>$tmp.err \
  193.     | sed \
  194.     -e 's/"//g' \
  195.     -e 's/$/ /' \
  196.     -e "s/^[^ ]* /ncpu=/" \
  197.     -e 's/ / cpulist="/' \
  198.     -e 's/"$/""/' \
  199.     -e 's/ $/"/'`
  200.  
  201.     if [ -z "$cpulist" -o "$ncpu" -lt 1 ]
  202.     then
  203.     echo "Cannot get CPU inventory for host $host" >$tmp.msg
  204.     cat $tmp.err >>$tmp.msg
  205.     _pmview_error -f $tmp.msg
  206.     # NOTREACHED
  207.     fi
  208.  
  209.     echo "$cpulist" | tr ' ' '\012' >$tmp.cpu
  210.  
  211.     if [ -z "$cpuargs" ]
  212.     then
  213.     # sort list
  214.     #
  215.     if grep cpu: $tmp.cpu >/dev/null
  216.     then
  217.         # Origin series name style
  218.         cpulist=`sed -e 's/:/./' $tmp.cpu \
  219.              | sort -t. +1 -2n +2 -3n +3 -4 \
  220.              | sed -e 's/\./:/'`
  221.     else
  222.         # CPU names for older systems
  223.         cpulist=`sed -e 's/cpu/cpu./' $tmp.cpu \
  224.              | sort -t. +1 -2n \
  225.              | sed -e 's/\.//'`
  226.     fi
  227.     else
  228.     # restrict based on command line args
  229.     #
  230.     for cpu in $cpuargs
  231.     do
  232.         if grep "$cpu" $tmp.cpu >/dev/null
  233.         then
  234.         :
  235.         else
  236.         echo "CPU \"$cpu\" not in the CPU inventory ..." >$tmp.msg
  237.         fmt $tmp.cpu | sed -e 's/^/    /' >>$tmp.msg
  238.         _pmview_error -f $tmp.msg
  239.         # NOTREACHED
  240.         fi
  241.     done
  242.     cpulist="$cpuargs"
  243.     ncpu=`echo $cpulist | awk '{ print NF }'`
  244.     fi
  245.  
  246.     # shape the base geometry for the scene
  247.     #
  248.     if [ $ncpu -le $maxrowlen ]
  249.     then
  250.     nrows=1
  251.     ncols=$ncpu
  252.     elif $force
  253.     then
  254.     nrows=`echo $ncpu $maxrowlen | nawk ' \
  255.         { x = $1 / $2; y = $1 % $2; if (y > 0) ++x; printf "%d\n", x; }'`
  256.     ncols=$maxrowlen
  257.     else
  258.     case $algorithm in
  259.         a)    # this algorithm doesn't work at the moment
  260.         # (the exit condition is not robust enough)
  261.         nrows=1
  262.         ncols=1
  263.         bound=1
  264.         num=0
  265.         while [ $num -gt $ncols -o $num -lt $bound ]
  266.         do
  267.             nrows=`expr $nrows \* 2`
  268.             ncols=`expr $ncpu / $nrows`
  269.             bound=`expr $ncols / 2`
  270.             num=`expr $nrows \* 4`
  271.         done
  272.         ncols=`echo $ncpu $nrows | nawk ' { x = $1 / $2; y = $1 % $2; \
  273.                   if (y > 0) ++x; printf "%d\n", x }'`
  274.         ;;
  275.         b)
  276.         # use a ratio for rows:columns of 1:8
  277.         #
  278.         nrows=`echo $ncpu | nawk ' { x = sqrt ($1 / 8.0);
  279.                 y = int (x); if (y < x) ++y; print y }'`
  280.         ncols=`expr $ncpu + $nrows - 1`
  281.         ncols=`expr $ncols / $nrows`
  282.         ;;
  283.         k)
  284.         nrows=`expr $ncpu + $maxrowlen - 1`
  285.         nrows=`expr $nrows / $maxrowlen`
  286.         ncols=`expr $ncpu + $nrows - 1`
  287.         ncols=`expr $ncols / $nrows`
  288.     esac
  289.     fi
  290.  
  291.     cat <<End-of-File >$tmp.conf
  292. pmview Version 2.0
  293. #
  294. # mpvis
  295. #
  296. #_scale 1.05
  297. _gridSpace $gridspace
  298. _gridHeight 2
  299. End-of-File
  300.  
  301.     if $have_intr
  302.     then
  303.     echo "_colorlist cpu ( green2 cyan2 yellow2 red2 blue2 )" >>$tmp.conf
  304.     else
  305.     echo "_colorlist cpu ( green2 cyan2 red2 blue2 )" >>$tmp.conf
  306.     fi
  307.     echo "_grid 0 0 hide ( # outer grid" >>$tmp.conf
  308.  
  309.     # build rows from front-to-back of scene
  310.     # fill rows with CPUs from left-to-right
  311.     #
  312.     y=`expr $nrows \* 2 - 2`
  313.     col=0
  314.     rowlist=""
  315.     labels=""
  316.     for cpu in $cpulist
  317.     do
  318.     if [ $col -eq 0 ]
  319.     then
  320.         rowlist="$cpu"
  321.     else
  322.         rowlist="$rowlist,$cpu"
  323.     fi
  324.     $showinst && labels="$labels \"`echo $cpu | sed -e 's/cpu:*//'`\""
  325.     col=`expr $col + 1`
  326.     if [ $col -eq $ncols ]
  327.     then
  328.         _do_row
  329.         col=0
  330.         rowlist=""
  331.         labels=""
  332.         y=`expr $y - 2`
  333.     fi
  334.     done
  335.     [ $col -gt 0 ] && _do_row
  336.     echo ")" >>$tmp.conf
  337.  
  338.     if [ $nrows -eq 1 ]
  339.     then
  340.     # remove unnecessary _grid for a single row
  341.     #
  342.     sed -e '/^    _grid/d' -e '/^    )/d' <$tmp.conf >$tmp.tmp
  343.     mv $tmp.tmp $tmp.conf
  344.     fi
  345.  
  346. fi
  347.  
  348. $verbose && cat $tmp.conf
  349.  
  350. eval pmview <$tmp.conf $args -title "'$titleArg'" -xrm "'*iconName: mpvis'"
  351.  
  352. exit
  353.